﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using pingjia.bll;
using PJTY.dal;

public partial class views_Login : System.Web.UI.Page
{
    ConsumerService customeSrv = new ConsumerService();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Unnamed2_Click(object sender, EventArgs e)
    {

    }

    protected void Unnamed1_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            //调用CustomerService类中的CheckLogin()方法检查输入的用户名和密码是否正确
            int userID = customeSrv.CheckLogin(txtName.Text.Trim(), txtPwd.Text.Trim());
            if (userID > 0)   //用户名和密码正确
            {
                Session.Clear();   //清理Session中保存的内容        
                if (txtName.Text.Trim() == "1")  //管理员登录。
                {
                    Session["AdminId"] = userID;
                    Session["AdminName"] = txtName.Text;
                    Response.Redirect("customer/first.aspx?name= " + txtName.Text, false);
                }
                else  //一般用户登录
                {
                    Session["userID"] = userID;
                    Session["username"] = txtName.Text;
                    Response.Redirect("admin/Products.aspx?name=" + txtName.Text, false);
                }
            }
            else  //用户名或密码错误
            {
                Response.Write("<script>alert('用户名或密码错误')</script>");
            }
        }

    }
}